
import { request } from "../../utils/request";
import config from "../../utils/config";

const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        custom: wx.getMenuButtonBoundingClientRect(),
        picUrl: config.picUrl,
        userInfo: {},
        page:1,
        last_page:1,
        endHide:true,
        list:[]
    },
    onLoad(options) {
        wx.hideShareMenu()
        var timer = setInterval(() => {
            var userInfo = wx.getStorageSync('userInfo')
            if (userInfo) {
                this.setData({ userInfo })
                this.getList()
                clearInterval(timer)
            }
        }, 500)
    },
    getList(){
        request({
            url:'/miniprogram/user/getMyFollowList',
            data:{user_id:this.data.userInfo.id,page:this.data.page},
            type:'post'
        }).then(res=>{
            this.setData({list:res.data,last_page:res.last_page})
        })
    },
    delMyFollow(e){
        request({url:"/miniprogram/user/delFans",data:{id:e.currentTarget.dataset.id}}).then(res=>{
            if(res.code == 200){
                var list = this.data.list
                list.splice(e.currentTarget.dataset.index,1)
                this.setData({list})
            }else{
                wx.showToast({title:res.msg,icon:'none'})
            }
        })
    },
    onReachBottom() {
        if(this.data.page >= this.data.last_page){
            this.setData({endHide:false})
            return false;
        }
        this.setData({page:this.data.page+1})
        this.getList()
    },
})